package com.doit.day06

object _04_偏函数 {



  def aaa()={
    println("基哥，你好坏哦，我好喜欢")
  }

  def main(args: Array[String]): Unit = {

    val list :List[Any]= List(1,"zss",2,'a',true,(1,"lss"),1.9)

    //需求：我要将这里面所有的数值类型(整数类型或者小数类型) * 10 返回给我，其他的都丢掉
    //==》 List(10,20,19)

    //只将整数类型，小数类型保留，其他的都不要
   /* val list1: List[Any] = list.filter(word => {
      word.isInstanceOf[Int] || word.isInstanceOf[Double]
    })

    val doubles: List[Double] = list1.map(word => {
      if( word.isInstanceOf[Int]){
        word.asInstanceOf[Int] * 10.0
      }else{
        word.asInstanceOf[Double] * 10.0
      }
    })*/

   val par =  new PartialFunction[Any,Double] {
      //就类似于filter
      override def isDefinedAt(word: Any) = word.isInstanceOf[Int] || word.isInstanceOf[Double]

      //类似于map
      override def apply(word: Any) = {
        if( word.isInstanceOf[Int]){
          word.asInstanceOf[Int] * 10.0
        }else{
          word.asInstanceOf[Double] * 10.0
        }
      }
    }

    val doubles: List[Double] = list.collect(par)
    doubles.foreach(println)










  }
}
